/**
 * Building 
 * Define Building objects
 **/
var Building = function() {
	this.conf = null;
	this.pop = null
	this.position = null;

	this.init = function(p) {
		log('*** INIT BUILDING ***');
		this.conf = BuildingConf.pickup();
		this.name = this.conf.name;
		this.position = p;
	}

	this.update = function() {
		if (this.pop == null)
			this.calculatePop();
	}

	this.isWalkable = function() {
		return this.conf.walkable;
	}

	this.getColor = function() {
		return this.conf.color;
	}

	this.getPop = function() {
		return this.pop;
	}

	this.calculatePop = function() {
		var idx = 0;
		do {
			var x = this.position.x + this.conf.pop[idx].x;
			var y = this.position.y + this.conf.pop[idx].y;
			var cell = game.mMap.getCell({x: x, y: y});
			if (cell.isWalkable())
				this.pop = {x: x, y: y};

		} while (idx < this.conf.pop.length && this.pop == null);
	}

	this.onClick = function() {
		// TODO
		// Pop d'un ouvrier - building.cfg.js
		this.conf.action(this.pop);
		this.conf.action;
	}

};